package com.ax.api.route.base.drugadministration;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.ax.api.route.util.RouteConfig;

@RestController
@RequestMapping("/drugadministration")
public class DrugAdministrationRoute {
	 @Autowired
	 LoadBalancerClient loadBalancerClient;
	 @Autowired
	 RestTemplate restTemplate;
	 
	/**
	 * 菜单页面的跳转
	 */
	@GetMapping("/sys/drugAdministration")
	String drugAdministration(Model model) {
		String url = geturl("/sys/drugAdministration");
		return restTemplate.getForObject(url, String.class);
	}
	 
	/**
	 * queryDrugAdministrationDep
	 * remote_base
	 * 药监查询(模块:药监部门)
	 */   
	@GetMapping("/queryDrugAdministrationDep")
	public String queryDrugAdministrationDep(@RequestParam Map<String,Object> map){
		String value = "?drugDepId={drugDepId}";
		String url = geturl("/sys/drugAdministration/queryDrugAdministrationDep")+value;
		return restTemplate.getForObject(url, String.class,map);
  }
	
   /**
	 * insertDrugDep
	 * remote_base
	 * 药监保存(模块:药监部门)
	 */   
	@GetMapping("/insertDrugDep")
	public String insertDrugDep(@RequestParam Map<String,Object> map){
		String value = "?drugDepCode={drugDepCode}&drugDepName={drugDepName}&firstLetter={firstLetter}&fullName={fullName}&parentDrugDepId={parentDrugDepId}&registrarId={registrarId}&registrarName={registrarName}&flag={flag}";
		String url = geturl("/sys/drugAdministration/insertDrugDep")+value;
		return restTemplate.getForObject(url, String.class,map);
  }
	
	/**
	 * edit
	 * remote_base
	 * 药监修改(模块:药监部门)*跳转修改页面
	 */   
	@GetMapping("/edit/drugAdministration")
	public String edit(String id){
		String value = "/id="+id;
		String url = geturl("/sys/drugAdministration/edit")+value;
		return restTemplate.getForObject(url, String.class,id);
  }
	
	/**
	 * add
	 * remote_base
	 * 药监增加(模块:药监部门)*跳转增加页面
	 */   
	@GetMapping("/add/drugAdministration")
	public String addDrugAdministration(String pId){
		String value = "/pId="+pId;
		String url = geturl("/sys/drugAdministration/add")+value;
		return restTemplate.getForObject(url, String.class,pId);
  }
	/**
	 * updateDrugDep
	 * remote_base
	 * 药监修改(模块:药监部门)
	 */  
	@GetMapping("/updateDrugDep")
	public String updateDrugDep(@RequestParam Map<String,Object> map){
		String value = "?drugDepCode={drugDepCode}&drugDepId={drugDepId}&drugDepName={drugDepName}&firstLetter={firstLetter}&fullName={fullName}&parentDrugDepId={parentDrugDepId}&registrarId={registrarId}&registrarName={registrarName}&flag={flag}";
		String url = geturl("/sys/drugAdministration/updateDrugDep")+value;
		return restTemplate.getForObject(url,String.class,map);
  }
	/**
	 * updateState
	 * remote_base
	 * 药监状态修改(模块:药监部门)
	 */  
	@GetMapping("/updateState")
	public String updateState(Map<String,Object> map){
		String value = "?parameter={parameter}&flag={flag}";
		String url = geturl("/sys/drugAdministration/updateState")+value;
		return restTemplate.getForObject(url,String.class,map);
  }
	
	   private String geturl(String path){
		 ServiceInstance serviceInstance = loadBalancerClient.choose(RouteConfig.BASE_ROUTE);
		 StringBuffer bf = new StringBuffer("http://");
		 bf.append(serviceInstance.getHost());
		 bf.append(":");
		 bf.append(serviceInstance.getPort());
		 bf.append(path);
		 return bf.toString();
		   
	   }
}
